package com.say.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.say.bean.domain.Chat;

@Repository
public interface ChatDao extends JpaRepository<Chat, String> {

	
	@Query(nativeQuery = true, value = "SELECT t.* from chat t WHERE t.`status`=1 AND ((t.user_id=?1 AND t.to_user_id=?2) OR (t.user_id=?2 AND t.to_user_id=?1 )) AND t.id>?3 ORDER BY t.create_time ASC")
	public List<Chat> findChatByIntervalPagePage(String userId,String toUserId, String maxChatId);
	
	@Query(nativeQuery = true, value = "update chat set status = 0  where status=1 and (user_id = ?1 or to_user_id = ?1) ")
	@Modifying
    public void updateChatStautsByUser(String userId);
	
}
